let logger = require("log4js").getLogger("default");
const Menu = require("../../../../models/setting/menuModel.js");
const { buildErrObject } = require("../../../../utils/buildErrObject");
const findMenuList = function (req = {}) {
	return new Promise(async (resolve, reject) => {
		Menu.aggregate([
			{
				$match: {
					$and: [{ is_delete: false }],
				},
			},
			{
				$project: {
					id: 1,
					pid: 1,
					_id: 0,
					title: 1,
					type: 1,
					path: 1,
					sort: 1,
					is_show: 1,
					icon: 1,
					status: 1,
					create_time: 1,
				},
			},
		])
			.sort({ create_time: 1 })
			.exec(async (err, doc) => {
				if (err) {
					logger.error(err);
					reject(buildErrObject(422, err));
				} else {
					resolve(doc);
				}
			});
		return;
	});
};

module.exports = { findMenuList };
